<template>
  <view class="container">
    <div style="padding: 20rpx">
      <div class="jigou_box">
        <div class="title">机构：{{ name }}</div>
        <view class="jigou_switch_check" @click="addUser"> 新增员工 </view>
      </div>

      <div class="jigou_box teshu" v-for="(item, index) in list" :key="index">
        <div class="title">
          <div style="font-size: 26rpx">{{ item.name }}</div>
          <div style="font-size: 26rpx">{{ item.mobile }}</div>
        </div>

        <div style="display: flex; flex-direction: column">
          <view class="jigou_switch_check" @click="addUser(item)">
            编辑
          </view>
          <view class="jigou_switch_check" style="margin-top: 12rpx; background-color: #e00e1b"
            @click="deleteJiGou(item)">
            删除
          </view>
        </div>

      </div>
    </div>
  </view>
</template>

<script>
import { getStaff, delStaff } from "@/api/index.js";
export default {

  data() {
    return {
      content: "",
      keyword: "",
      // 列表
      list: [],
      name: ""
    };
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onShow(options) {
    this.getData();

    this.name = uni.getStorageSync("curHospitalName")
  },

  methods: {
    async getData() {
      this.list.length = 0
      try {
        const _res = await getStaff({
          hospital_id: uni.getStorageSync("curHospital"),
          page: 1,
          limit: 100
        })



        _res.list.forEach((_d) => {
          this.list.push({
            ..._d,

          })
        })
      } catch (error) {

      }
    },
    /**
     * 返回上一页
     */
    goBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    addUser(_data) {
      if (_data.id) {
        // 跳到新增用户页面
        uni.navigateTo({
          url: "/pages/adminPage/yuangong/edit" + "?id=" + _data.id,
        });
      } else {
        uni.navigateTo({
          url: "/pages/adminPage/yuangong/edit",
        });
      }

    },
    deleteJiGou(_data) {
      // 二次弹窗确认
      uni.showModal({
        title: "提示",
        content: "确定要删除吗？",
        success: async (res) => {
          if (res.confirm) {
            try {
              uni.showLoading({
                title: "正在删除...",
              });
              await delStaff({
                id: _data.id,
              });

              uni.showToast({
                title: "删除成功",
              });
              this.getData()
            } catch (error) {

              uni.hideLoading();
            }
          }
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  min-height: 100vh;
  background: #ebebeb;
}

.custom_btn {
  width: 100rpx;
  height: 50rpx;
  border-radius: 4rpx;
  background-color: rgba(78, 147, 221, 1);
  color: rgba(255, 255, 255, 1);
  font-size: 26rpx;
  text-align: center;
  font-family: PingFangSC-regular;
}

.jigou_box {
  // width: 760rpx;
  height: 88rpx;
  line-height: 40rpx;
  border-radius: 24rpx;
  background-color: rgba(255, 255, 255, 1);
  color: rgba(16, 16, 16, 1);
  font-size: 28rpx;
  text-align: center;
  font-family: PingFangSC-regular;

  padding: 20rpx 40rpx;
  display: flex;
  justify-content: space-between;

  margin-bottom: 15rpx;

  .title {
    line-height: 46rpx;
    color: rgba(16, 16, 16, 1);
    font-size: 32rpx;
    text-align: left;
    font-family: PingFangSC-regular;
  }

  .jigou_switch {
    width: 122rpx;
    border-radius: 8rpx;
    background-color: rgba(78, 147, 221, 1);
    color: rgba(255, 255, 255, 1);
    font-size: 26rpx;
    font-family: PingFangSC-regular;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .jigou_switch_check {
    width: 122rpx;
    line-height: 38rpx;
    border-radius: 8rpx;
    background-color: rgba(81, 224, 14, 1);
    color: rgba(255, 255, 255, 1);
    font-size: 26rpx;
    text-align: center;
    font-family: PingFangSC-regular;
  }
}

.teshu {
  height: auto !important;
}
</style>
